package com.jade.framework.web.spring;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

/**
 * 根据请求类型返回响应的处理页面。
 *
 * @author dwzhang
 * @version 1.0 14-7-16 下午1:59
 */
public class AjaxExceptionResolver extends SimpleMappingExceptionResolver
{
    protected String determineViewName(Exception ex, HttpServletRequest request)
    {
        String viewName = super.determineViewName(ex, request);
        //判断是为ajax请求
        String requestedWith = request.getHeader("x-requested-with");
        String accept = request.getHeader("Accept");
        if (StringUtils.isNotBlank(requestedWith) && accept.contains("application/json")) {
            return viewName + "-ajax";
        }
        return viewName;
    }
}
